package com.hopital5.zhangyz.vo.request;

import com.hopital5.zhangyz.model.Label;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LabelVoRequest extends BaseRequest {
    private Long labelId;
    private String name;

    @Override
    public Specification<Label> toSpecification() {
        return ((root, query, cb) -> {
            List<Predicate> predicates = new ArrayList<>();
            if (predicates.isEmpty()) {
                return cb.conjunction();
            } else {
                return cb.and(predicates.toArray(new Predicate[predicates.size()]));
            }
        });
    }
}
